package com.moli.iov.protocol.model.realtime;


/*
 * 文件名： AlarmData.java
 *
 * 创建日期： 2016年12月1日
 *
 * Copyright(C) 2016, by <a href="mailto:liws@xingyuanauto.com">liws</a>.
 *
 * 原始作者: liws
 *
 */

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.google.common.primitives.Bytes;
import com.moli.iov.protocol.codec.Serialize;
import com.moli.iov.protocol.enums.realtime.AlarmLevelTag;
import com.moli.iov.protocol.enums.realtime.GeneralAlarmStateTag;
import com.moli.iov.protocol.model.EntityBytesLen;



/**
 * 报警数据
 *
 * 此报警数据实体 包含可充电储能装置故障,驱动电机故障,发动机故障,其他故障
 * 通过相应addXXX方法进行故障添加
 *
 * @author <a href="mailto:liws@xingyuanauto.com">liws</a>
 *
 * @version $Revision$
 *
 * @since 2016年12月1日
 */
@Serialize(unit="byte",isBigEndian=true)
public class AlarmReq implements Serializable,EntityBytesLen{

	 /**
	 */
	public static final long serialVersionUID = 1L;

	/**
	 * 故障级别
	 */
	@Serialize(unit="byte",offset=0,size=1)
	public AlarmLevelTag alarmLevel;
	/**
	 * 通用报警状态
	 */
	@Serialize(unit="byte",offset=1,size=4)
	public GeneralAlarmStateTag generalAlarmState;

	/**
	 * 可充电储能装置故障总数
	 */
	@Serialize(unit="byte",offset=5,size=1)
	public byte storingDeviceFaultSum;

	/**
	 * 可充电储能装置故障字节序数据
	 */
	public byte[] storingDeviceFaultData;

	/**
	 * 此属性后续属性为 变长内容
	 *
	 * 故在此方法中进行后续数据的解析赋值
	 *
	 * @param storingDeviceFaultData
	 */
	@Serialize(unit="byte",offset=6,size=-1)
	public void setStoringDeviceFaultData(byte[] bytes) {
		// 获取sysCode偏移量和长度
		int currentOffset = 0;
		int currentSize = this.storingDeviceFaultSum*4;
		byte[] currnetBytes = new byte[currentSize];
		System.arraycopy(bytes, currentOffset, currnetBytes, 0, currentSize);
		this.storingDeviceFaultData = currnetBytes;
		bytesLen+=currentSize;

		// 获取 驱动电机故障总数 偏移量和长度
		currentOffset = currentOffset + currentSize;
		currentSize = 1;
		this.driveMotorFaultSum = bytes[currentOffset];
		bytesLen+=currentSize;

		// 获取 驱动电机故障字节序数据 偏移量和长度
		currentOffset = currentOffset + currentSize;
		currentSize = this.driveMotorFaultSum*4;
		currnetBytes = new byte[currentSize];
		System.arraycopy(bytes, currentOffset, currnetBytes, 0, currentSize);
		this.driveMotorFaultData = currnetBytes;
		bytesLen+=currentSize;

		// 获取 发动机故障总数 偏移量和长度
		currentOffset = currentOffset + currentSize;
		currentSize = 1;
		this.engineFaultSum = bytes[currentOffset];
		bytesLen+=currentSize;

		// 获取 发动机故障字节序数据 偏移量和长度
		currentOffset = currentOffset + currentSize;
		currentSize = this.engineFaultSum*4;
		currnetBytes = new byte[currentSize];
		System.arraycopy(bytes, currentOffset, currnetBytes, 0, currentSize);
		this.engineFaultData = currnetBytes;
		bytesLen+=currentSize;

		// 获取 其他故障总数 偏移量和长度
		currentOffset = currentOffset + currentSize;
		currentSize = 1;
		this.otherFaultSum = bytes[currentOffset];
		bytesLen+=currentSize;

		// 获取 其他故障字节序数据 偏移量和长度
		currentOffset = currentOffset + currentSize;
		currentSize = this.otherFaultSum*4;
		currnetBytes = new byte[currentSize];
		System.arraycopy(bytes, currentOffset, currnetBytes, 0, currentSize);
		this.otherFaultData = currnetBytes;
		bytesLen+=currentSize;
	}

	public byte[] getStoringDeviceFaultData() {
		return storingDeviceFaultData;
	}

	/**
	 * 驱动电机故障总数
	 */
	public byte driveMotorFaultSum;

	/**
	 * 驱动电机故障字节序数据
	 *
	 */
	public byte[] driveMotorFaultData;


	public byte[] getDriveMotorFaultData() {
		return driveMotorFaultData;
	}

	/**
	 * 发动机故障总数
	 */
	public byte engineFaultSum;

	/**
	 * 发动机故障字节序数据
	 */
	public byte[] engineFaultData;


	/**
	 * 其他故障总数
	 */
	public byte otherFaultSum;

	/**
	 * 其他故障字节序数据
	 */
	public byte[] otherFaultData;

	/**
	 * 获取解码字节序长度 默认已知长度 6 根据解析值 进行累加
	 */
	public int bytesLen = 6;

	 /**
	 *
	 */
	@Override
	public int getBytesLen() {
		return bytesLen;
	}

	public AlarmLevelTag getAlarmLevel() {
		return alarmLevel;
	}

	public void setAlarmLevel(AlarmLevelTag alarmLevel) {
		this.alarmLevel = alarmLevel;
	}

	public GeneralAlarmStateTag getGeneralAlarmState() {
		return generalAlarmState;
	}

	public void setGeneralAlarmState(GeneralAlarmStateTag generalAlarmState) {
		this.generalAlarmState = generalAlarmState;
	}

	public byte getStoringDeviceFaultSum() {
		return storingDeviceFaultSum;
	}

	public void setStoringDeviceFaultSum(byte storingDeviceFaultSum) {
		this.storingDeviceFaultSum = storingDeviceFaultSum;
	}

	public byte getDriveMotorFaultSum() {
		return driveMotorFaultSum;
	}

	public void setDriveMotorFaultSum(byte driveMotorFaultSum) {
		this.driveMotorFaultSum = driveMotorFaultSum;
	}

	public byte getEngineFaultSum() {
		return engineFaultSum;
	}

	public void setEngineFaultSum(byte engineFaultSum) {
		this.engineFaultSum = engineFaultSum;
	}

	public byte[] getEngineFaultData() {
		return engineFaultData;
	}

	public void setEngineFaultData(byte[] engineFaultData) {
		this.engineFaultData = engineFaultData;
	}

	public byte getOtherFaultSum() {
		return otherFaultSum;
	}

	public void setOtherFaultSum(byte otherFaultSum) {
		this.otherFaultSum = otherFaultSum;
	}

	public byte[] getOtherFaultData() {
		return otherFaultData;
	}

	public void setOtherFaultData(byte[] otherFaultData) {
		this.otherFaultData = otherFaultData;
	}

	public void setDriveMotorFaultData(byte[] driveMotorFaultData) {
		this.driveMotorFaultData = driveMotorFaultData;
	}

	 /**
	 *
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("AlarmReq [alarmLevel=");
		builder.append(alarmLevel);
		builder.append(", generalAlarmState=");
		builder.append(generalAlarmState);
		builder.append(", storingDeviceFaultSum=");
		builder.append(storingDeviceFaultSum);
		builder.append(", storingDeviceFaultData=");
		builder.append(Arrays.toString(storingDeviceFaultData));
		builder.append(", driveMotorFaultSum=");
		builder.append(driveMotorFaultSum);
		builder.append(", driveMotorFaultData=");
		builder.append(Arrays.toString(driveMotorFaultData));
		builder.append(", engineFaultSum=");
		builder.append(engineFaultSum);
		builder.append(", engineFaultData=");
		builder.append(Arrays.toString(engineFaultData));
		builder.append(", otherFaultSum=");
		builder.append(otherFaultSum);
		builder.append(", otherFaultData=");
		builder.append(Arrays.toString(otherFaultData));
		builder.append(", bytesLen=");
		builder.append(bytesLen);
		builder.append("]");
		return builder.toString();
	}
}
